/**
 * getFollower node file
 */

var GetFollower = function(accountId, options){
	this.accountId = accountId;
	this.success = options.success;
	this.error = options.error;
	this.options = options;
	this.get();
};

GetFollower.prototype._success = function(data){
	if(typeof this.success == 'function') {
		this.success(data);
	}
};

GetFollower.prototype._error = function(code, message){
	if(typeof this.error == 'function') {
		this.error(code, message);
	}
};


GetFollower.prototype.check = function(nextStatement){
	var self = this;
	Mysql.query("SELECT COUNT(*) AS c1 FROM Account WHERE id="+Mysql.escape(self.accountId)+" LIMIT 1", function(error, results){
		if(error) {
			console.log('Mysql error: '+error);
			self._error(9999, 'Mysql error');
			return;
		}
		if(results[0].c1 == 0) {
			self._error(9999, 'Not found account');
			return;
		}
		nextStatement();
	});
};

GetFollower.prototype.get = function(){
	var self = this;
	self.check(function(){
		Mysql.query("SELECT Follow.id,Follow.accountId,Account.name FROM Follow JOIN Account ON Account.id=Follow.accountId WHERE Follow.accountId="+Mysql.escape(self.accountId), function(error, results){
			if(error) {
				console.log('Mysql error: '+error);
				self._error(9999, 'Mysql error');
				return;
			}
			self._success(results);
		});
	});
};

module.exports = GetFollower;